﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using System.Security;
using FredCK.FCKeditorV2;
using System.Threading;
using System.Globalization;
using BLL.Store;

public partial class Admin_AddEditDepartment : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
         
        if (!IsPostBack)
        {
            if (!string.IsNullOrEmpty(this.Request.QueryString["ID"]))
            {
                if (this.User.Identity.IsAuthenticated && (this.User.IsInRole("Administrators")))
                {
                    dvwDepartment.ChangeMode(DetailsViewMode.Edit);
                    UpdateTitle();
                }
                else
                    throw new SecurityException("You are not allowed to edit existent products!");
            }
        }
    }
    private void UpdateTitle()
    {
        lblNewProduct.Visible = (dvwDepartment.CurrentMode == DetailsViewMode.Insert);
        lblEditProduct.Visible = !lblNewProduct.Visible;
    }
    
    protected void dvwDepartment_DataBound(object sender, EventArgs e)
    {
        if (dvwDepartment.CurrentMode == DetailsViewMode.Insert)
        {
            //AsyncFileUpload asyn = dvwDepartment.FindControl("AsyncFileUploadSimple1") as AsyncFileUpload;
            //asyn.pictureUrl = "";
        }

        if (dvwDepartment.CurrentMode == DetailsViewMode.Edit)
        {
            if (!string.IsNullOrEmpty(this.Request.QueryString["ID"]))
            {
                //Departments1 dep1 = Departments1.GetDepartment1ByID(int.Parse(this.Request["ID"]));
                Department dep = Department.GetDepartmentByID(int.Parse(this.Request["ID"]));

            }
        }
    }
    protected void dvwDepartment_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
    {
        e.NewValues["ParentID"] = (dvwDepartment.FindControl("ddlDepartments") as DropDownList).SelectedValue;
        if (Session["PictureId"] != null)
            e.NewValues["PictureID"] = (int)Session["PictureId"];
    }
    protected void dvwDepartment_ItemInserting(object sender, DetailsViewInsertEventArgs e)
    {
        e.Values["ParentID"] = (dvwDepartment.FindControl("ddlDepartments") as DropDownList).SelectedValue;
        if (Session["PictureId"] != null)
            e.Values["PictureID"] = (int)Session["PictureId"];
    }
}
